package com.aldobucchi.hierarchy
{


	import com.aldobucchi.ds.container.utils.ContainerUtil;
	import com.aldobucchi.utils.AbstractTest;



	/**
	 * 
	 * 
	 * 
	 * @author aldo.bucchi@gmail.com
	 * 
	 */
	public class HierarchyUtilTest extends AbstractTest
	{
		

		private var a:SimpleHierarchicalConcept = new SimpleHierarchicalConcept( "a" );
		private var aa:SimpleHierarchicalConcept = new SimpleHierarchicalConcept( "aa" );
		private var aaa:SimpleHierarchicalConcept = new SimpleHierarchicalConcept( "aaa" );
	
		private var b:SimpleHierarchicalConcept = new SimpleHierarchicalConcept( "b" );
		private var bb:SimpleHierarchicalConcept = new SimpleHierarchicalConcept( "bb" );
		private var bbb:SimpleHierarchicalConcept = new SimpleHierarchicalConcept( "bbb" );
	
	
		
		public function test_optimize( ):void
		{
		
			
			assertOpt( [ a, aa, aaa ] , true	, [ a ] );
			assertOpt( [ a, aa, aaa ] , false	, [ aaa ] );
			
			assertOpt( [ a, aa ] , true, [ a ] );
			assertOpt( [ a, aa ] , false, [ aa ] );
			
			assertOpt( [ a, aa, aaa, b, bb, bbb ] , true, [ a, b ] );
			assertOpt( [ a, aa, aaa, b, bb, bbb ] , false, [ aaa, bbb ] );


		}
		
		
		
		


		

		/**
		 * 
		 * Custom assertion method for ease of testing
		 * 
		 * @param concepts
		 * @param removeHigher
		 * @param result
		 * 
		 */		
		private function assertOpt( concepts:Array, removeHigher:Boolean, result:Array ):void
		{
			
			var res:Array = HierarchyUtil.optimize( concepts, removeHigher );		
		
			if ( ! ContainerUtil.eq( res, result ) )
			{
				fail( "Results were not as expected" );
			}
		
		}



	}
	
}